class MenuScene extends Phaser.Scene {
    constructor() {
        super('MenuScene');
    }

    create() {
        console.log('开始创建MenuScene');
        
        // 创建背景
        this.background = this.add.tileSprite(0, 0, this.game.config.width, this.game.config.height, 'background')
            .setOrigin(0, 0);
        console.log('背景创建完成');

        // 计算各个元素的位置
        const titleY = 100;
        const buttonY = Math.floor(this.game.config.height * 0.35); // 按钮位置在屏幕35%处
        const instructionsY = buttonY + 150; // 说明文本在按钮下方150像素处
        const versionY = this.game.config.height - 30;

        // 创建标题
        const title = this.add.text(this.game.config.width / 2, titleY, '太空战机', {
            fontSize: '48px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#00000080',
            padding: { x: 20, y: 10 }
        }).setOrigin(0.5);
        console.log('标题创建完成');

        // 创建开始按钮
        const startButton = this.add.text(this.game.config.width / 2, buttonY, '开始游戏', {
            fontSize: '32px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#4CAF50',
            padding: { x: 20, y: 10 }
        })
        .setOrigin(0.5)
        .setInteractive()
        .on('pointerover', () => startButton.setStyle({ fill: '#ff0' }))
        .on('pointerout', () => startButton.setStyle({ fill: '#fff' }))
        .on('pointerdown', () => {
            console.log('开始按钮被点击');
            this.scene.start('GameScene');
        });
        console.log('开始按钮创建完成');

        // 创建游戏说明
        const instructions = this.add.text(this.game.config.width / 2, instructionsY, 
            '游戏说明：\n' +
            '• 使用方向键或触摸移动飞机\n' +
            '• 自动射击\n' +
            '• 收集能量道具\n' +
            '• 躲避敌机\n' +
            '• 击毁敌机获得分数', {
            fontSize: '18px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#00000080',
            padding: { x: 15, y: 10 },
            align: 'center',
            lineSpacing: 10
        }).setOrigin(0.5);
        console.log('游戏说明创建完成');

        // 创建版本信息
        const version = this.add.text(this.game.config.width / 2, versionY, 'v1.0.0', {
            fontSize: '16px',
            fill: '#fff',
            fontFamily: 'Arial',
            backgroundColor: '#00000080',
            padding: { x: 10, y: 5 }
        }).setOrigin(0.5);
        console.log('版本信息创建完成');

        // 添加标题动画
        this.tweens.add({
            targets: title,
            y: titleY + 20,
            duration: 2000,
            yoyo: true,
            repeat: -1,
            ease: 'Sine.easeInOut'
        });

        // 添加调试信息
        console.log('屏幕尺寸:', this.game.config.width, 'x', this.game.config.height);
        console.log('标题位置:', titleY);
        console.log('按钮位置:', buttonY);
        console.log('说明位置:', instructionsY);
        console.log('版本位置:', versionY);
    }

    update() {
        // 背景滚动效果
        this.background.tilePositionY -= 0.5;
    }
} 